//
//  MyCenterViewController.m
//  AppointmentForCar
//
//  Created by Herron on 16/10/2.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "MyCenterViewController.h"
#import "SettingViewController.h"
#import "OrdersTableViewController.h"
#import "ModifyUserInfoViewController.h"
#import "DriverModel.h"

@interface MyCenterViewController ()
@property (weak, nonatomic) IBOutlet UILabel *NameLabel;
@property (weak, nonatomic) IBOutlet UIButton *iconImage;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@end

@implementation MyCenterViewController

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    NSString *driverId = [UserAccountManager shareUserManager].user.driverId;
    [NetWork postNetWorkWithUrl:kURLDriverInfo parame:@{@"driverId":driverId} successBlock:^(NSDictionary *dic) {
        NSLog(@"司机信息dic = %@", dic);
        NSDictionary *driverDic = dic[@"data"];
        UserModel *user = [UserModel mj_objectWithKeyValues:driverDic];
        self.NameLabel.text = user.driverNickName;
        self.iconImageView.urlPath = user.driverAvatarUrl;
        
    } errorBlock:^(id error) {
        [HUDManager showWarningWithText:@"网络异常"];
    }];

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(reloadAvatar:) name:kNoticeChangeAvatarImage object:nil];
    [center addObserver:self selector:@selector(reloadName:) name:kNoticeChangeName object:nil];
}

- (void)reloadAvatar:(NSNotification *)sender {
    self.iconImageView.urlPath = [UserAccountManager shareUserManager].user.driverAvatarUrl;
}

- (void)reloadName:(NSNotification *)sender {
    self.NameLabel.text = [UserAccountManager shareUserManager].user.driverNickName;
}

- (void)viewWillAppear:(BOOL)animated {
    [self.mm_drawerController setShowsShadow:YES];
    [self.mm_drawerController setMaximumLeftDrawerWidth:200];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = YES;

}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kNoticeChangeAvatarImage object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kNoticeChangeName object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - event method
- (IBAction)historyOrderClick:(id)sender {
    [self.mm_drawerController setMaximumLeftDrawerWidth:kSCREEN_WIDTH];
    [self.mm_drawerController setShowsShadow:NO];
    OrdersTableViewController *vc = [[OrdersTableViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)settingClick:(id)sender {
    [self.mm_drawerController setMaximumLeftDrawerWidth:kSCREEN_WIDTH];
    [self.mm_drawerController setShowsShadow:NO];
    SettingViewController *vc = [[SettingViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)userInfoClick:(id)sender {
    [self.mm_drawerController setMaximumLeftDrawerWidth:kSCREEN_WIDTH];
    [self.mm_drawerController setShowsShadow:NO];
    ModifyUserInfoViewController *vc = [[ModifyUserInfoViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
